﻿using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Text;

namespace InternetSpiderLib.Scenes.Actions
{
    /// <summary>
    /// 网页数据提取器
    /// </summary>
    public class HtmlDataExtractionAction : HtmlBaseDataExtractionAction
    {
        public IHtmlDataExtractionItem[] DataExtractions { get; set; }

        public override void Extraction(SceneContext data)
        {
            HtmlDocument document = data?.Context?.Get<HtmlDocument>();
            if (document == null)
                return;

            foreach (var item in DataExtractions ?? new IHtmlDataExtractionItem[0])
            {
                var temp = item.Extraction(document);
                if (temp != null)
                    data.Result.AddRange(temp);
            }
        }
    }
}
